<title>奖学金</title><link href="http://hzoi.com/tomorrow.css" rel="stylesheet"><div class="ui existing segment"><pre><code><span class="pl-cm">/*</span>
<span class="pl-cm">3 5 70</span>
<span class="pl-cm">30 25</span>
<span class="pl-cm">50 21</span>
<span class="pl-cm">20 20</span>
<span class="pl-cm">5 18</span>
<span class="pl-cm">35 30</span>
<span class="pl-cm">*/</span>
<span class="pl-cp">#include</span><span class="pl-cpf">&lt;bits/stdc++.h&gt;</span><span class="pl-cp"></span>
<span class="pl-k">using</span> <span class="pl-k">namespace</span> <span class="pl-n">std</span><span class="pl-p">;</span>
<span class="pl-kt">int</span> <span class="pl-n">n</span><span class="pl-p">,</span><span class="pl-n">c</span><span class="pl-p">,</span><span class="pl-n">tot</span><span class="pl-p">,</span><span class="pl-n">f</span><span class="pl-p">[</span><span class="pl-mi">200005</span><span class="pl-p">],</span><span class="pl-n">g</span><span class="pl-p">[</span><span class="pl-mi">200005</span><span class="pl-p">];</span>
<span class="pl-k">struct</span> <span class="pl-n">node</span><span class="pl-p">{</span> <span class="pl-kt">int</span> <span class="pl-n">sc</span><span class="pl-p">,</span><span class="pl-n">mn</span><span class="pl-p">;</span> <span class="pl-p">}</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-mi">200005</span><span class="pl-p">];</span>
<span class="pl-n">priority_queue</span><span class="pl-o">&lt;</span><span class="pl-kt">int</span><span class="pl-o">&gt;</span> <span class="pl-n">q</span><span class="pl-p">;</span>
<span class="pl-kr">inline</span> <span class="pl-kt">int</span> <span class="pl-nf">read</span><span class="pl-p">(){</span>
    <span class="pl-kt">int</span> <span class="pl-n">ret</span><span class="pl-o">=</span><span class="pl-mi">0</span><span class="pl-p">,</span><span class="pl-n">ff</span><span class="pl-o">=</span><span class="pl-mi">1</span><span class="pl-p">;</span><span class="pl-kt">char</span> <span class="pl-n">ch</span><span class="pl-o">=</span><span class="pl-n">getchar</span><span class="pl-p">();</span>
    <span class="pl-k">while</span><span class="pl-p">(</span><span class="pl-o">!</span><span class="pl-n">isdigit</span><span class="pl-p">(</span><span class="pl-n">ch</span><span class="pl-p">)){</span><span class="pl-k">if</span><span class="pl-p">(</span><span class="pl-n">ch</span><span class="pl-o">==</span><span class="pl-sc">&#39;-&#39;</span><span class="pl-p">)</span> <span class="pl-n">ff</span><span class="pl-o">=-</span><span class="pl-n">ff</span><span class="pl-p">;</span><span class="pl-n">ch</span><span class="pl-o">=</span><span class="pl-n">getchar</span><span class="pl-p">();}</span>
    <span class="pl-k">while</span><span class="pl-p">(</span><span class="pl-n">isdigit</span><span class="pl-p">(</span><span class="pl-n">ch</span><span class="pl-p">)){</span><span class="pl-n">ret</span><span class="pl-o">=</span><span class="pl-n">ret</span><span class="pl-o">*</span><span class="pl-mi">10</span><span class="pl-o">+</span><span class="pl-p">(</span><span class="pl-n">ch</span><span class="pl-o">^</span><span class="pl-mi">48</span><span class="pl-p">);</span><span class="pl-n">ch</span><span class="pl-o">=</span><span class="pl-n">getchar</span><span class="pl-p">();}</span>
    <span class="pl-k">return</span> <span class="pl-n">ret</span><span class="pl-o">*</span><span class="pl-n">ff</span><span class="pl-p">;</span>
<span class="pl-p">}</span>
<span class="pl-kr">inline</span> <span class="pl-kt">bool</span> <span class="pl-nf">cmp</span><span class="pl-p">(</span><span class="pl-n">node</span> <span class="pl-n">A</span><span class="pl-p">,</span><span class="pl-n">node</span> <span class="pl-n">B</span><span class="pl-p">){</span> <span class="pl-k">return</span> <span class="pl-n">A</span><span class="pl-p">.</span><span class="pl-n">sc</span><span class="pl-o">&lt;</span><span class="pl-n">B</span><span class="pl-p">.</span><span class="pl-n">sc</span><span class="pl-p">;</span> <span class="pl-p">}</span>
<span class="pl-kt">signed</span> <span class="pl-nf">main</span><span class="pl-p">(){</span>
    <span class="pl-n">n</span><span class="pl-o">=</span><span class="pl-n">read</span><span class="pl-p">(),</span><span class="pl-n">c</span><span class="pl-o">=</span><span class="pl-n">read</span><span class="pl-p">(),</span><span class="pl-n">tot</span><span class="pl-o">=</span><span class="pl-n">read</span><span class="pl-p">();</span>
    <span class="pl-k">for</span><span class="pl-p">(</span><span class="pl-kt">int</span> <span class="pl-n">i</span><span class="pl-o">=</span><span class="pl-mi">1</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">&lt;=</span><span class="pl-n">c</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">++</span><span class="pl-p">)</span>
        <span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">sc</span><span class="pl-o">=</span><span class="pl-n">read</span><span class="pl-p">(),</span> <span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-o">=</span><span class="pl-n">read</span><span class="pl-p">();</span>
    <span class="pl-n">sort</span><span class="pl-p">(</span><span class="pl-n">a</span><span class="pl-o">+</span><span class="pl-mi">1</span><span class="pl-p">,</span><span class="pl-n">a</span><span class="pl-o">+</span><span class="pl-n">c</span><span class="pl-o">+</span><span class="pl-mi">1</span><span class="pl-p">,</span><span class="pl-n">cmp</span><span class="pl-p">);</span>
    <span class="pl-kt">int</span> <span class="pl-n">sum</span><span class="pl-o">=</span><span class="pl-mi">0</span><span class="pl-p">;</span>
    <span class="pl-k">for</span><span class="pl-p">(</span><span class="pl-kt">int</span> <span class="pl-n">i</span><span class="pl-o">=</span><span class="pl-mi">1</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">&lt;=</span><span class="pl-n">n</span><span class="pl-o">/</span><span class="pl-mi">2</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">++</span><span class="pl-p">){</span>
        <span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">push</span><span class="pl-p">(</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-p">);</span>
        <span class="pl-n">sum</span><span class="pl-o">+=</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-p">;</span>
    <span class="pl-p">}</span>
    <span class="pl-k">for</span><span class="pl-p">(</span><span class="pl-kt">int</span> <span class="pl-n">i</span><span class="pl-o">=</span><span class="pl-n">n</span><span class="pl-o">/</span><span class="pl-mi">2</span><span class="pl-o">+</span><span class="pl-mi">1</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">&lt;=</span><span class="pl-n">c</span><span class="pl-o">-</span><span class="pl-n">n</span><span class="pl-o">/</span><span class="pl-mi">2</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">++</span><span class="pl-p">){</span>
        <span class="pl-n">f</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">]</span><span class="pl-o">=</span><span class="pl-n">sum</span><span class="pl-p">;</span>
        <span class="pl-k">if</span><span class="pl-p">(</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-o">&lt;</span><span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">top</span><span class="pl-p">()){</span>
            <span class="pl-n">sum</span><span class="pl-o">-=</span><span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">top</span><span class="pl-p">();</span>
            <span class="pl-n">sum</span><span class="pl-o">+=</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-p">;</span>
            <span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">pop</span><span class="pl-p">();</span>
            <span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">push</span><span class="pl-p">(</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-p">);</span>
        <span class="pl-p">}</span>
    <span class="pl-p">}</span>
    <span class="pl-k">while</span><span class="pl-p">(</span><span class="pl-o">!</span><span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">empty</span><span class="pl-p">())</span> <span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">pop</span><span class="pl-p">();</span>
    <span class="pl-n">sum</span><span class="pl-o">=</span><span class="pl-mi">0</span><span class="pl-p">;</span>
    <span class="pl-k">for</span><span class="pl-p">(</span><span class="pl-kt">int</span> <span class="pl-n">i</span><span class="pl-o">=</span><span class="pl-n">c</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">&gt;=</span><span class="pl-n">c</span><span class="pl-o">-</span><span class="pl-n">n</span><span class="pl-o">/</span><span class="pl-mi">2</span><span class="pl-o">+</span><span class="pl-mi">1</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">--</span><span class="pl-p">)</span>
        <span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">push</span><span class="pl-p">(</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-p">),</span> <span class="pl-n">sum</span><span class="pl-o">+=</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-p">;</span>
    <span class="pl-k">for</span><span class="pl-p">(</span><span class="pl-kt">int</span> <span class="pl-n">i</span><span class="pl-o">=</span><span class="pl-n">c</span><span class="pl-o">-</span><span class="pl-n">n</span><span class="pl-o">/</span><span class="pl-mi">2</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">&gt;=</span><span class="pl-n">n</span><span class="pl-o">/</span><span class="pl-mi">2</span><span class="pl-o">+</span><span class="pl-mi">1</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">--</span><span class="pl-p">){</span>
        <span class="pl-n">g</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">]</span><span class="pl-o">=</span><span class="pl-n">sum</span><span class="pl-p">;</span>
        <span class="pl-k">if</span><span class="pl-p">(</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-o">&lt;</span><span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">top</span><span class="pl-p">()){</span>
            <span class="pl-n">sum</span><span class="pl-o">-=</span><span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">top</span><span class="pl-p">();</span>
            <span class="pl-n">sum</span><span class="pl-o">+=</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-p">;</span>
            <span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">pop</span><span class="pl-p">();</span>
            <span class="pl-n">q</span><span class="pl-p">.</span><span class="pl-n">push</span><span class="pl-p">(</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-p">);</span>
        <span class="pl-p">}</span>
    <span class="pl-p">}</span>
    <span class="pl-k">for</span><span class="pl-p">(</span><span class="pl-kt">int</span> <span class="pl-n">i</span><span class="pl-o">=</span><span class="pl-n">c</span><span class="pl-o">-</span><span class="pl-n">n</span><span class="pl-o">/</span><span class="pl-mi">2</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">&gt;=</span><span class="pl-n">n</span><span class="pl-o">/</span><span class="pl-mi">2</span><span class="pl-o">+</span><span class="pl-mi">1</span><span class="pl-p">;</span><span class="pl-n">i</span><span class="pl-o">--</span><span class="pl-p">)</span>
        <span class="pl-k">if</span><span class="pl-p">(</span><span class="pl-n">f</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">]</span><span class="pl-o">+</span><span class="pl-n">g</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">]</span><span class="pl-o">+</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">mn</span><span class="pl-o">&lt;=</span><span class="pl-n">tot</span><span class="pl-p">)</span> <span class="pl-k">return</span> <span class="pl-n">printf</span><span class="pl-p">(</span><span class="pl-s">&quot;%d&quot;</span><span class="pl-p">,</span><span class="pl-n">a</span><span class="pl-p">[</span><span class="pl-n">i</span><span class="pl-p">].</span><span class="pl-n">sc</span><span class="pl-p">),</span> <span class="pl-mi">0</span><span class="pl-p">;</span>
    <span class="pl-n">printf</span><span class="pl-p">(</span><span class="pl-s">&quot;-1&quot;</span><span class="pl-p">);</span>
    <span class="pl-k">return</span> <span class="pl-mi">0</span><span class="pl-p">;</span>
<span class="pl-p">}</span>
</cpde></pre></div>